#include "Clientstdafx.h"
#include "DynLibManager.h"
#include "DynLib.h"

namespace Apo
{
 
 
    //-----------------------------------------------------------------------
	DynLibManager::DynLibManager()
	{
	}
	//-----------------------------------------------------------------------
    DynLib* DynLibManager::load( const String& filename)
    {

		DynLib** i = mLibList.find(filename);
		if (i != NULL)
		{
			return *i;
		}
		else
		{
	        DynLib* pLib = new DynLib(filename);
			pLib->load(); 
			mLibList.insert( (filename) ,pLib);
        	//mLibList[filename] = pLib;
	        return pLib;
		}
    }
	//-----------------------------------------------------------------------
	void DynLibManager::unload(DynLib* lib)
	{
 		DynLib** i = mLibList.find(lib->getName());
 		if (i != NULL)
 		{
 			mLibList.erase((*i)->getName());
 		}
 		lib->unload();
		delete lib;
	}
	//-----------------------------------------------------------------------
    DynLibManager::~DynLibManager()
    {
        // Unload & delete resources in turn
//          for( DynLibList::iterator it = mLibList.begin(); it != mLibList.end(); ++it )
//          {
//              it->second->unload();
//              delete it->second;
//          }
		for (int i = 0 ;mLibList.size();++i )
		{
			DynLib* lib = mLibList.at(i) ;
		}
 
        // Empty the list
        mLibList.clear();
    }
}
